/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package com.bishe.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bishe.entity.AskLeave;
import com.bishe.entity.resp.CommonResult;
import com.bishe.entity.resp.CommonValidList;
import com.bishe.param.AskLeaveAddParam;
import com.bishe.param.AskLeaveEditParam;
import com.bishe.param.AskLeaveIdParam;
import com.bishe.param.AskLeavePageParam;
import com.bishe.service.AskLeaveService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Map;

/**
 * ask_leave控制器
 *
 * @author wwz
 * @date  2024/03/11 13:21
 */
@Api(tags = "请假信息控制器")
@RestController
@Validated
public class AskLeaveController {

    @Resource
    private AskLeaveService askLeaveService;

    @ApiOperationSupport(order = 0)
    @ApiOperation("学生请假人数统计")
    @GetMapping("/biz/askleave/tj")
    public CommonResult<Map<Object, Object>> tj() {
        return CommonResult.data(askLeaveService.tj());
    }


    /**
     * 获取ask_leave分页
     *
     * @author wwz
     * @date  2024/03/11 13:21
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取ask_leave分页")
    @SaCheckPermission("/biz/askleave/page")
    @GetMapping("/biz/askleave/page")
    public CommonResult<Page<AskLeave>> page(AskLeavePageParam askLeavePageParam) {
        return CommonResult.data(askLeaveService.page(askLeavePageParam));
    }

    /**
     * 添加ask_leave
     *
     * @author wwz
     * @date  2024/03/11 13:21
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加ask_leave")
    @SaCheckPermission("/biz/askleave/add")
    @PostMapping("/biz/askleave/add")
    public CommonResult<String> add(@RequestBody @Valid AskLeaveAddParam askLeaveAddParam) {
        askLeaveService.add(askLeaveAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑ask_leave
     *
     * @author wwz
     * @date  2024/03/11 13:21
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑ask_leave")
    @SaCheckPermission("/biz/askleave/edit")
    @PostMapping("/biz/askleave/edit")
    public CommonResult<String> edit(@RequestBody @Valid AskLeaveEditParam askLeaveEditParam) {
        askLeaveService.edit(askLeaveEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除ask_leave
     *
     * @author wwz
     * @date  2024/03/11 13:21
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除ask_leave")
    @SaCheckPermission("/biz/askleave/delete")
    @PostMapping("/biz/askleave/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                       CommonValidList<AskLeaveIdParam> askLeaveIdParamList) {
        askLeaveService.delete(askLeaveIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取ask_leave详情
     *
     * @author wwz
     * @date  2024/03/11 13:21
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取ask_leave详情")
    @SaCheckPermission("/biz/askleave/detail")
    @GetMapping("/biz/askleave/detail")
    public CommonResult<AskLeave> detail(@Valid AskLeaveIdParam askLeaveIdParam) {
        return CommonResult.data(askLeaveService.detail(askLeaveIdParam));
    }


    @ApiOperationSupport(order = 6)
    @ApiOperation("我的请假列表")
    @SaCheckPermission("/biz/askleave/myAskLeave")
    @GetMapping("/biz/askleave/myAskLeave")
    public CommonResult<List<AskLeave>> myAskLeave( ) {
        return CommonResult.data(askLeaveService.myAskLeave());
    }
}
